package com.pureut.quality.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.quality.domain.dto.QualityProductionFreezeDto;
import com.pureut.quality.domain.vo.ThawVo;
import com.pureut.quality.service.QualityProductionFreezeService;
import com.pureut.quality.domain.vo.QualityProductionFreezeVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 生产冻结表控制层
 * Author:C
 * Date:2023/02/07 14:07
 * @DESC
 */
@RestController
@RequestMapping("/quality-production-freeze")
public class QualityProductionFreezeController extends BaseController {

    @Resource
    QualityProductionFreezeService qualityProductionFreezeService;

    /**
     * 生产冻结列表
     */
    @RequiresPermissions("quality:inspecmanage:productfreeze:list")
    @GetMapping("/list")
    public TableDataInfo getList(QualityProductionFreezeVo qualityProductionFreezeVo) {
        startPage();
        //查询检验方案配置列表
        List<QualityProductionFreezeDto> list = qualityProductionFreezeService.getFreezeList(qualityProductionFreezeVo);
        return getDataTable(list);
    }

    /**
     * 冻结查询
     */
    @GetMapping("/getFreeze")
    public AjaxResult getFreeze(QualityProductionFreezeVo qualityProductionFreezeVo) {
        return AjaxResult.success(qualityProductionFreezeService.getFreeze(qualityProductionFreezeVo));
    }

    /**
     * 冻结
     */
    @RequiresPermissions("quality:inspecmanage:productfreeze:freeze")
    @PostMapping("/freeze")
    @Log(title = "冻结", businessType = BusinessType.INSERT)
    public AjaxResult freeze(@RequestBody QualityProductionFreezeVo qualityProductionFreezeVo) {
        return toAjax(qualityProductionFreezeService.freeze(qualityProductionFreezeVo));
    }

    /**
     * 解冻
     */
    @RequiresPermissions("quality:inspecmanage:productfreeze:thaw")
    @PostMapping("/thaw")
    @Log(title = "解冻", businessType = BusinessType.UPDATE)
    public AjaxResult thaw(@Validated @RequestBody ThawVo thawVo) {
        return toAjax(qualityProductionFreezeService.thaw(thawVo));
    }

    /**
     * 查看
     */
    @GetMapping("/view/{ids}")
    public AjaxResult getView(@PathVariable("ids") String ids) {
        return AjaxResult.success(qualityProductionFreezeService.getView(ids));
    }

    /**
     * 品质处理
     */
    @RequiresPermissions("quality:inspecmanage:productfreeze:qualityTreatment")
    @PostMapping("/qualityTreatment")
    @Log(title = "品质处理", businessType = BusinessType.UPDATE)
    public AjaxResult qualityTreatment(@RequestBody ThawVo thawVo) {
        return toAjax(qualityProductionFreezeService.qualityTreatment(thawVo));
    }

    /**
     * 小卷打包数据新增（fegin调用）
     */
    @PostMapping("/smallRollAdd")
    public boolean smallRollAdd(@RequestBody QualityProductionFreezeVo qualityProductionFreezeVo) {
        return qualityProductionFreezeService.smallRollAdd(qualityProductionFreezeVo);
    }

}
